package com.kgc.scd.service.impl;

import com.kgc.scd.service.OrderService;
import com.kgc.scd.service.SeckillService;
import com.kgc.scd.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created On : 2022/11/23.
 * <p>
 * Author : Administrator
 * <p>
 * Description: OrderServiceImpl
 */
@Slf4j
@Service
public class SeckillServiceImpl implements SeckillService {


    @Autowired
    private RedisUtils redisUtils;
    @Override
    public boolean checkBuyUserCount(String pid) {
        return redisUtils.incr("seckill:"+pid,1)>Integer.parseInt(redisUtils.get("qgGoods:" + pid).toString()) * 2;
    }

    @Override
    public boolean checkBuyUserBought(String userId, String pid) {
        return !redisUtils.lock(userId+":qgUserlock:"+pid,null,10000);
    }

    @Override
    public boolean checkProdStockLocked(String pid) {
        return !redisUtils.lock("qgGoodlock:"+pid,null,60000);
    }
}
